'use strict';

angular.module('xianwan')
    .factory('NW', ['$window', '$rootScope', 'Constant', 'LocalStorage', 'SettingConstant', '$timeout', 'SystemSetting', '$interval', '$injector',
        function ($window, $rootScope, Constant, LocalStorage, SettingConstant, $timeout, SystemSetting, $interval, $injector) {
            
            let NW = null;
            let win = null;
            NW = require('nw.gui');
            win = NW.Window.get();

            // 记录所有已注册的快捷键，用于取消注册
            let registeredShortcuts = {};

            // iframesLinksOpenInCurrent 中的所有 iframe 中的链接需要在当前 iframe 打开
            let iframesLinksOpenInCurrent = [];

            window.onbeforeunload = function () {
                window.tray && window.tray.remove();

                closeOpenedWin && closeOpenedWin();
            };
            
            let init = function () {
                /* 初始化前重置状态，防止刷新控制台导致上次绑定的事件没有被取消 */
                resetStatus();
                
                if (window.require) {
                    initTray();

                    bindShowNotificationFn();

                    bindOthersFn();

                    listenerEvent();

                    // clear cache when init
                    // require('nw.gui').App.clearCache();
                }
            }

            window.onbeforeunload = function () {
                window.tray && window.tray.remove();
            };

            let handleReopen = function () {console.log(`in handleReopen...`);
                // if (window.location.href.indexOf('main') === -1) {
                //     return;
                // }

                // let Domain = $injector.get('Domain');
                // try {
                //     Domain.getDomainSettings()
                //         .then(function (data) {
                //             console.log(`update domain settings success:`, data);
                //         }, function (data) {
                //             console.log(`update domain settings error:`, data);
                //         });
                // } catch (e) {
                //     console.log(`update domain settings error:${e.message}`);
                // }

                // try {
                //     Domain.getChatFileWhitelist()
                //         .then(function (data) {
                //             console.log(`111:`, data);
                //             $rootScope.commonConfig && ($rootScope.commonConfig.chatFileDownload = data);
                //         })
                //         .catch(function (err) {
                //             console.log(`222:`, err);
                //         })
                // } catch (e) {
                //     console.log(`updateChatFileWhitelist error: ${e.message}`);
                // }

                // if (Constant.BEHAVIOR_LOG === true) {console.log('handle logs reopen');
                //     let UserBehaviorLogs = $injector.get('UserBehaviorLogs');
                //     let logTypes = UserBehaviorLogs.getLogTypes();
                //     let logType = logTypes['clientVisit'];
                //     let timestamp = Date.now();

                //     UserBehaviorLogs.initClientVisitLog(timestamp)
                //         .then(function (data) {
                //             console.log(`initClientVisitLog success`);
                //         }, function (data) {
                //             console.error(`initClientVisitLog error`);
                //         });

                //     logType = logTypes['appVisit'];
                //     let currentLogInfo = UserBehaviorLogs.getCurrentLogInfo(logType);
                //     if (currentLogInfo && currentLogInfo.app) {
                //         UserBehaviorLogs.initAppVisitLog(timestamp, currentLogInfo.app)
                //             .then(function (data) {
                //                 console.log(`initLogByType success: appVisit`);
                //             }, function (data) {
                //                 console.error(`initLogByType error: appVisit`);
                //             });
                //     }

                //     logType = logTypes['tabVisit'];
                //     currentLogInfo = UserBehaviorLogs.getCurrentLogInfo(logType);
                //     if (currentLogInfo && currentLogInfo.app) {
                //         UserBehaviorLogs.initTabVisitLog(timestamp, currentLogInfo.app)
                //             .then(function (data) {
                //                 console.log(`initTabVisitLog success: tabVisit`);
                //             }, function (data) {
                //                 console.error(`initTabVisitLog error: tabVisit`);
                //             });
                //     }
                // }
            };

            /**
             * @param {*} resetFlag: default false
             */
            let handleClose = function (resetFlag) {
                // if (window.location.href.indexOf('main') === -1) {
                //     return;
                // }

                // if (Constant.BEHAVIOR_LOG === true) {
                //     console.log('handleClose');
                    
                //     let UserBehaviorLogs = $injector.get('UserBehaviorLogs');
                //     let timestamp = Date.now();
                //     UserBehaviorLogs.resetCurrentLogInfo(timestamp, resetFlag);
                // }
            };
            
            function listenerEvent() {

                // 设置变量记录APP的打开与隐藏状态
                NW.App.on('reopen', function (url) { //再次打开事件
                    console.info('reopen');
                    
                    handleUrl(url);
                    updateTrayIfNecessary();
                    if (!$window.showOrHide) {
                        win.show();
                        $window.showOrHide = true;

                        handleReopen && handleReopen();
                    } else {
                        // mac 客户端  reopen 时，showOrHide 为 true,原因待查 @20180929
                        if (process.platform === 'darwin') {
                            handleReopen && handleReopen();
                        }
                    }
                    $window.isHide = false;
                });

                NW.App.on('open', function (url) { //打开事件
                    console.info('open');
                    handleUrl(url);
                    if (!$window.showOrHide) {
                        win.show();
                        $window.showOrHide = true;
                    }
                    $window.isHide = false
                });

                win.on('close', function (operation) {
                    console.info('close');
                    handleClose &&  handleClose();
                    win.hide();
                    $window.showOrHide = false;
                    $window.isHide = true;

                    if (operation) {console.log('close true');
                        win.removeAllListeners();
                        win.close(true);
                        
                        // force to exit
                        NW.App.quit();
                        return;
                    }
                });

                $window.showOrHide = true;

                win.on('focus', function () {
                    // NW.App.registerGlobalHotKey(togglePanelShortcut);
                    win.show();
                    $window.showOrHide = true;

                    updateTrayIfNecessary();
                    if ($window.isHide && process.platform !== "darwin") {
                        // mock windows reopen event
                        console.info('mock reopen');
                        handleReopen && handleReopen();
                    }
                    $window.isHide = false;
                });

                win.on('blur', function () {
                    // NW.App.unregisterGlobalHotKey(togglePanelShortcut);
                    $window.showOrHide = false;
                });

                win.on('minimize', function () {
                    console.info('minimize');
                    $window.isHide = true;
                    handleClose && handleClose();
                });

                win.on('maximize', function (evt) {
                    console.info('maximize');
                });

                win.on('unmaximize', function (evt) {
                    console.info('unmaximize');
                });

                win.on('hide', function (evt) {
                    console.info('hide');
                });

                win.on('restore', function (evt) {
                    console.info('restore');
                });
                
            }
            
            function updateTrayIfNecessary(updateAttention) {
                var allUnread = 0;
                if ($rootScope.messages) {
                    for (var item in $rootScope.messages) {
                        if ($rootScope.messages[item].remind && $rootScope.messages[item].unreadMessageNum > 0) {
                            allUnread += $rootScope.messages[item].unreadMessageNum;
                        }
                        if ($rootScope.messages[item].remind && $rootScope.messages[item].markUnreadNum > 0) {
                            allUnread += $rootScope.messages[item].markUnreadNum;
                        }
                    }
                    allUnread = allUnread >= 0 ? allUnread : 0; // 双保险, 有出现allUnread为负数的bug
                    if (allUnread == 0) {
                        setTrayIcon('false');
                    }
                    if (allUnread == 0 && updateAttention) {
                        win.requestAttention(true);
                    }
                }
            }

            /* handle url when open window */
            /* xianwan://auth:login?token=123 */
            /* xianwan://auth:logout */
            /* xianwan://chat?userId=abc */
            // "C:\xianwan2\xianwan\xianwan.exe" --original-process-start-time=13158815558117800 xianwan://meeting/?type=umeeting&action=join&id=xxx
            // todo window和mac下launchUrl可能会有区别
            function handleUrl(launchUrl) {
                if (!launchUrl) {
                    return;
                }
                let protocol = Constant.URL_PROTOCOL + '://';
                if (launchUrl.indexOf(protocol) == -1) {
                    console.log('wrong protocol...');
                    return;
                }
                launchUrl = launchUrl.substring(launchUrl.indexOf(protocol));

                let launchStr = launchUrl.substr(protocol.length);
                let launchArr = launchStr.split('?');
                
                let launchType = launchArr[0];
                let launchParams = launchArr[1];

                showWindow();

                function handleAuthLogin (token) {
                    console.log('handleAuthLogin:', token);
                }

                function handleAuthLogout () {
                    console.log('handleAuthLogout...');
                }

                function handleChatById (userId) {
                    openChat(userId);
                }

                function parseQueryParams (query) {
                    if (!query) {
                        return [];
                    }

                    let arr = query.split('&');
                    let tmp = [];
                    let params = {};

                    arr.forEach(function (item, index) {
                        tmp = item.split('=');
                        params[tmp[0]] = tmp[1];
                    });

                    return params;
                }

                /* open/reopen by protocol */
                // if (launchType.indexOf(':') === -1) { /* for old param: userId */
                //     let userId = launchUrl.substr(protocol.length);
                //     handleChatById(userId);
                //
                //     return;
                // }
                let queryParams = parseQueryParams(launchParams);
                let hostname = launchType.split(':')[0];
                let pathname = launchType.split(':')[1];
                
                switch (hostname) {
                    case 'auth': {
                        if (pathname === 'login') {
                            handleAuthLogin(queryParams['token']);
                        } else if (pathname === 'logout') {
                            handleAuthLogout();
                        } else {
                            // others
                        }
                        break;
                    }
                    case 'chat': {
                        handleChatById(queryParams['userId']);
                        break;
                    }
                    case 'meeting/': {
                        if (window.joinUmeeting) {
                            window.joinUmeeting({
                                meetingId: queryParams['id']
                            })
                        }
                        break;
                    }
                    /**
                     * default: open chat by username
                     * note: userId represents username
                     */
                    default: {
                        let userId = launchStr;
						if (userId[userId.length - 1] === '/') {
							userId = userId.substring(0, userId.length - 1);
						}
						openChat(userId);
						break;
                    }
                }

                /* 
                if (url && url.startsWith(protocol)) {
                    var userId = url.substring(protocol.length, url.length);
                    openChat(userId);
                    return;
                }
                if (url && url.indexOf(protocol) > -1) {
                    var userId = url.substring(url.indexOf(protocol) + protocol.length, url.length -1);
                    openChat(userId);
                } 
                */
            }

            function openChat(userId) {
                if (window.openChatByUserId) {
                    window.openChatByUserId(userId);
                }
            }

            function showWindow() {
                win.show();
                window.focus();
                $window.showOrHide = true;
            }

            function registerShortcut() {
                // open search
                var openSearchShortcut = new NW.Shortcut(getShortcutOptionsByType(SettingConstant.OPEN_SEARCH));
                registeredShortcuts[SettingConstant.OPEN_SEARCH] = openSearchShortcut;
                NW.App.registerGlobalHotKey(openSearchShortcut);

                // screen shot
                if ($rootScope.commonConfig.isShowScreenShot) {
                    var screenshotShortcut = new NW.Shortcut(getShortcutOptionsByType(SettingConstant.SCREEN_SHOT));
                    registeredShortcuts[SettingConstant.SCREEN_SHOT] = screenshotShortcut;
                    NW.App.registerGlobalHotKey(screenshotShortcut);
                }
                // toggle panel
                var togglePanelShortcut = new NW.Shortcut(getShortcutOptionsByType(SettingConstant.TOGGLE_PANEL));
                registeredShortcuts[SettingConstant.TOGGLE_PANEL] = togglePanelShortcut;
                NW.App.registerGlobalHotKey(togglePanelShortcut);

                // Create a shortcut with |option|.
                var getMessageShortcut = new NW.Shortcut(getShortcutOptionsByType(SettingConstant.GET_MESSAGE));
                registeredShortcuts[SettingConstant.GET_MESSAGE] = getMessageShortcut;
                // Register global desktop shortcut, which can work without focus.
                NW.App.registerGlobalHotKey(getMessageShortcut);
                
            }

            /**
             * set crash dump directory
             */
            function setCrashDump () {
                var gui = require('nw.gui');
                var path = require('path');

                var dir = path.join(process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE, 'Documents', path.sep);
                gui.App.setCrashDumpDir(dir);
            }

            /**
             * tray initialize
             * if trayIcon is true, this function exec once.
             */
            function initTray() {
                if (!global.trayIcon) {
                    window.tray = new NW.Tray({
                        title: '',
                        icon: 'tray@2x.png',
                        iconsAreTemplates: false
                    });
                    // window platform rightclick tray quit app
                    if (process.platform !== "darwin") {
                        var menu = new NW.Menu();
                        menu.append(new NW.MenuItem({
                            label: '退出程序',
                            click: function () {
                                // handleClose && handleClose(true);

                                $timeout(function () {
                                    win.removeAllListeners();
                                    win.close(true);
                                    // force to exit
                                    NW.App.quit();
                                }, 500);
                            }
                        }));
                        window.tray.menu = menu;
                    }

                    // tray click event 
                    window.tray.on('click', function (event) {
                        window.focus();
                        win.show();
                        updateTrayIfNecessary();
                    });

                    // todo 点击menu bar的关闭窗口无法阻止关闭窗口
                    // if (win.menu) {
                    //     if (win.menu.items.length > 0) {
                    //         var osCloseMenu = win.menu.items[2].submenu.items[1];
                    //     }
                    // }

                }
            }

            /**
             * 点击打开消息提醒
             */
            function bindShowNotificationFn() {
                window.showNotification = function(icon, title, body, tag, isBing) {
                    if (icon && icon.match(/^\./)) {
                        icon = icon.replace('.', 'file://' + process.cwd());
                    }
                    var notification = new Notification(title, {
                        icon: icon,
                        body: body,
                        tag: tag
                    });

                    notification.onclick = function(event) {
                        win.show();
                        if (isBing) {
                            $rootScope.showBingDetail(this.tag);
                            return;
                        }
                        $rootScope.openChatPanel(event.target.tag);
                        angular.element('#chatContent').focus();
                        // writeLog("Notification clicked");
                    };

                    notification.onclose = function() {
                        // writeLog("Notification closed");
                        // NW.Window.get().focus();
                    };

                    notification.onshow = function() {
                        // writeLog("-----<br>" + title);
                    };

                    return notification;
                };
            }

            function bindOthersFn() {
                // Extend application menu for Mac OS
                if (process.platform == "darwin") {
                    var menu = new NW.Menu({
                        type: "menubar"
                    });
                    menu.createMacBuiltin && menu.createMacBuiltin(window.document.title);
                    NW.Window.get().menu = menu;
                }

                // 处理所有打开页面的逻辑
                // 有新的需求可以在这里增加逻辑处理
                win.on('new-win-policy', function (frame, url, policy) {
                    if (url.toLowerCase().indexOf('openExternal'.toLowerCase()) !== -1) {
                        policy.ignore();
                        window.openUrl(url);
                        // return false;
                    } else if (iframesLinksOpenInCurrent.indexOf(frame.name) > -1) {
                        policy.forceCurrent();
                    } else {
                        // others
                    }
                });
            }

            function setTrayIcon(state) {
                cancelTrayInterval();
                if (window.require && window.tray) {
                    if (state == 'true') {
                        let MAX_INTERVAL = 15;
                        let i = 0;
                        if (process.platform !== 'darwin') {
                            MAX_INTERVAL = Number.MAX_SAFE_INTEGER;
                            win.requestAttention(3);
                        }
                        window.trayInterval = $interval(function () {
                            if (i % 2) {
                                window.tray.icon = 'tray@2x.png';
                            } else {
                                window.tray.icon = 'tray_active@2x.png';
                            }
                            i++;
                        }, 500, MAX_INTERVAL);
                    } else {
                        window.tray.icon = 'tray@2x.png';
                    }
                }
            }

            function cancelTrayInterval() {
                if (window.trayInterval) {
                    $interval.cancel(window.trayInterval);
                }
            }

            function clearTrayIcon() {
                if (window.require) {
                    if (window.tray) {
                        window.tray.remove();
                    }
                }
            }

            function bindIframeADomClick(iframeName) {
                if (!window.require) return;
                var iframeWin = window.frames[iframeName];
                var opener = require("opener");

                angular.element(window.frames[iframeName].document).find('a').on('click', function (e) {
                    e.preventDefault();
                    opener(e.currentTarget.href);
                });

                window.frames[iframeName].window.open = function (url) {
                    opener(url);
                };

            }

            function addIframeLinksOpenInCurrent(iframeName) {
                iframesLinksOpenInCurrent.push(iframeName);
            }

            function _screenshot() {
                let successCallback = function () {
                    document.execCommand("Paste", false, "");
                };

                let resetWindowStatus = function () {
                    window.screening = false;
                    if (!$window.showOrHide) {
                        win.show();
                        $window.showOrHide = true;
                    }
                    angular.element('#chatContent').focus();
                };

                if (process.platform === 'darwin' && !window.screening) {
                    window.screening = true;
                    require('@ali/mac-screen-capture').captureScreen().then(function () {
                        resetWindowStatus();
                        successCallback();
                    }, function () {
                        resetWindowStatus();
                        console.log('fail');
                    })
                }
                if (process.platform === 'win32' && !window.screening && !$rootScope.commonConfig.isXpOS) {
                    window.screening = true;
                    require(process.cwd() + '\\' + 'screenshot-binding')(function(err, result) {
                        resetWindowStatus();
                        if (err) {
                            console.log(`window screen shot error:`, err);
                        }
                        if (result === 1) {
                            successCallback();
                        }
                    });
                }
                if (process.platform === 'win32' && !window.screening && $rootScope.commonConfig.isXpOS) {
                    let clipboard = require('nw.gui').Clipboard.get();
                    clipboard.clear();
                    window.screening = true;
                    let spawn = require('child_process').spawn;
                    let screenShotExe = path.join("xpScreen\\SnapShotW.exe");
                    let screenShotCp = spawn(screenShotExe);
                    screenShotCp.on('close', function() {
                        resetWindowStatus();
                        successCallback();
                    });
                    screenShotCp.on('error', function(err) {
                        resetWindowStatus();
                        console.error(err);
                    });
                }
            }
                
            function getShortcutOptionsByType(shortcutType) {
                let options = {};
                let settings = SystemSetting.getSystemSettings();

                switch(shortcutType) {
                    case 'OPEN_SEARCH': {
                        let openSearchOptions = {
                            key: settings.OPEN_SEARCH,
                            active: function() {
                                console.log('openSearch active', this.key);
                                if ($window.showOrHide === false) {
                                    win.show();
                                    $window.showOrHide = true;
                                }
                                /* 快捷键是全局的，如果此时 win 没有获取到焦点，即使对应的搜索框获取焦点，也无法正确输入 @20171115 */
                                win.focus();
                                $rootScope.$broadcast('searchFocus', {
                                    from: 'nwjs.service.js'
                                });
                            }, 
                            failed: function() {
                                console.log('Register open search shortcut failed!', this.key);
                            }
                        };

                        options = openSearchOptions;
                        break;
                    }
                    case 'SCREEN_SHOT': {
                        let screenshotOptions = {
                            key: settings.SCREEN_SHOT,
                            active: function () {
                                console.log('screenshot active', this.key);
                                if (window.require) {
                                    let screenshotShowWindow = SystemSetting.getSystemSettingByType(SettingConstant['SCREEN_SHOT_SHOW_WINDOW']);

                                    if (!screenshotShowWindow) {
                                        $timeout(function() {
                                            win.hide();

                                            $timeout(function() {
                                                _screenshot();
                                            }, 100);
                                        });
                                    } else {
                                        _screenshot();
                                    }
                                }
                            },
                            failed: function (msg) {
                                // :(, fail to register the |key| or couldn't parse the |key|.
                                // alert(msg);
                                console.log('Register screenshot shortkey failed!', this.key);
                            }
                        };

                        options = screenshotOptions;
                        break;
                    }
                    case 'TOGGLE_PANEL': {
                        let togglePanelOptions = {
                            key: settings.TOGGLE_PANEL,
                            active: function () {
                                console.log('togglePanel active', this.key);
                                if ($window.showOrHide) {
                                    win.hide();
                                    $window.showOrHide = false;

                                    handleClose && handleClose();
                                } else {
                                    win.show();
                                    window.focus();
                                    if (window.messageIdentifier) {
                                        $rootScope.openChatPanel(window.messageIdentifier);
                                        angular.element('#chatContent').focus();
                                        window.messageIdentifier = null;
                                    }
                                    $window.showOrHide = true;

                                    handleReopen && handleReopen();
                                }
                            },
                            failed: function () {
                                console.log('Register toggle panel shortcut failed!', this.key);
                            }
                        };

                        options = togglePanelOptions;
                        break;
                    } 
                    case 'GET_MESSAGE': {
                        // get message shortcut 
                        var getMessageOption = {
                            key: settings.GET_MESSAGE,
                            active: function () {
                                console.log('getMessage active', this.key);
                                window.focus();
                                if (window.messageIdentifier) {
                                    $rootScope.openChatPanel(window.messageIdentifier);
                                    angular.element('#chatContent').focus();
                                    window.messageIdentifier = null;
                                }
                            },
                            failed: function (msg) {
                                console.log('Register get message shortcut failed', this.key);
                            }
                        };

                        options = getMessageOption;
                        break;
                    } 
                    default: {
                        break;
                    }
                }

                return options;
            }

            function changeShortcut(changeType, keys) {
                let shortcut = null;
                shortcut = registeredShortcuts[changeType];

                let options = getShortcutOptionsByType(changeType);
                options.key = keys;

                NW.App.unregisterGlobalHotKey(shortcut);

                if (keys) {
                    shortcut = new NW.Shortcut(options);
                    registeredShortcuts[changeType] = shortcut;
                    NW.App.registerGlobalHotKey(shortcut);
                } else {
                    // delete registeredShortcuts[changeType];
                }
            }

            function unRegisterAllShortcutKeys() {
                let shortcut = null;
                for(var p in registeredShortcuts) {
                    if (registeredShortcuts.hasOwnProperty(p)) {
                        shortcut = registeredShortcuts[p];

                        NW.App.unregisterGlobalHotKey(shortcut);
                    }
                }

                shortcut = null;
            }

            /**
             * close windows which are opened before logout
             */
            function closeOpenedWin () {
                /**
                 * close image preview windows
                 */
				if (window.imagePreviewWin) {
					window.imagePreviewWin.forEach(function (childWin) {
						childWin.close(true);
					});
				}
            }

            function removeAllListeners() {
                win.removeAllListeners();
            }

            /* 用于退出时统一重置 NW 的一些状态 @20180426 */
            function resetStatus () {
                try {
                    clearTrayIcon();
                    unRegisterAllShortcutKeys();
                    closeOpenedWin();
                    removeAllListeners();
                } catch (e) {
                    console.error(`resetStatus error:${e.message}`);
                }
            }

            function getRegItem (regName) {
                const regedit = require('regedit');

                let regType = `HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run`;
                return new Promise(function (resolve, reject) {
                    regedit.list(regType, function(err, result) {
                        if (err) {
                            reject(err);
                        }
                        let regItem;
                        try {
                            regItem = result[regType]['values'][regName];
                        } catch (e) {
                            reject(e);
                        }
                        resolve(regItem);
                    });
                });
            }

            function setRegVal (regName, regVal) {
                const regedit = require('regedit');
                let regType = `HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run`;

                return new Promise(function (resolve, reject) {
                    let valuesToPut = {};
                    valuesToPut[regType] = {};
                    valuesToPut[regType][regName] = {
                        value: regVal,
                        type: 'REG_SZ'
                    };
                    regedit.putValue(valuesToPut, function(err) {
                        console.log(`put err:`, err);
                        if (err) {
                            reject(err);
                        }
                        resolve(`set reg val success..`);
                    });
                });
            }

            // 设置窗口大小与定位
            function setNwSize(width,height){
                return new Promise(function(resolve,reject){
                    win.show();
                    win.width = width;
                    win.height = height;
                    win.min_width = width;
                    win.min_height = height;
                    win.setPosition('center');// 屏幕居中
                    resolve();
                })
            }
            // 是否允许调整窗口大小
            function isResizable(isTrue){
                win.setResizable(isTrue);
            }

            return {
                init: init,
                setTrayIcon: setTrayIcon,
                clearTrayIcon: clearTrayIcon,
                bindIframeADomClick: bindIframeADomClick,
                addIframeLinksOpenInCurrent: addIframeLinksOpenInCurrent, 
                changeShortcut: changeShortcut, 
                registerShortcut: registerShortcut, 
                unRegisterAllShortcutKeys: unRegisterAllShortcutKeys,
                updateTrayIfNecessary: updateTrayIfNecessary, 
                closeOpenedWin: closeOpenedWin, 
                resetStatus: resetStatus,
                getRegItem: getRegItem,
                setRegVal: setRegVal,
                setNwSize:setNwSize,
                isResizable:isResizable
            }

        }
]);